<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1,user-scalable=no">
    <meta name="format-detection" content="telephone=no">
    <title>绑定手机</title>
    <link rel="stylesheet" href="__STATIC__/mall/css/zzsc.css">
</head>
<body>
<div class="form">
    <div class="div-phone">
        <label for="phone">手机</label><input type="text" id="phone" class="infos" placeholder="请输入手机" />
        <button class="send1" id="send" onclick="sends.send();">发送验证码</button>
        <!--<button style="height: 26px;text-decoration: none;line-height: 26px;padding: 2px;width: 80px;background: #AA8926;font-family: 宋体;color: #fff;font-size: 12px;text-align: center;display: block;float: left;border-radius: 2px;margin-left: 2px;">发送验证码</button>-->
    </div>
    <div class="div-ranks">
        <label for="ranks">验证码</label><input type="text" id="ranks" class="infos" placeholder="请输入验证码"  />
    </div>
    <div class="div-conform">
        <a href="javascript:;" class="conform" onclick="check();">提交</a>
    </div>
</div>
<script src="http://libs.baidu.com/jquery/1.9.0/jquery.js"></script>
<script>
    function check(){
        var ranks = $('#ranks').val();
        $.post("{:U('Bind/check')}",{'checkcode':ranks},function (data) {
            if (data.reg == 1) {
                alert(data.info);
                WeixinJSBridge.call('closeWindow');
            } else {
                alert(data.info);
            }
        });
    }
    var sends = {
        checked:1,
        send:function(){
            var numbers = /^1\d{10}$/;
            var val = $('#phone').val().replace(/\s+/g,""); //获取输入手机号码
            if($('.div-phone').find('span').length == 0 && $('.div-phone button').attr('class') == 'send1'){
                if(!numbers.test(val) || val.length ==0){
                    $('.div-phone').append('<span class="error">手机格式错误</span>');
                    return false;
                }
            }
            $.post("{:U('Bind/send')}",{'tel':$('#phone').val()},function (data) {
                if (data.reg == 1) {
                    if(numbers.test(val)){
                        var time = 300;
                        $('.div-phone span').remove();
                        var timer = setInterval(timeCountDown,1000);
                        function timeCountDown(){
                            if(time==0){
                                clearInterval(timer);
                                $('#send').addClass('send1').removeClass('send0').html("发送验证码");
                                $('#send').attr('disabled',false);
                                sends.checked = 1;
                                return false;
                            }
                            $('#send').attr('disabled',true);
                            $('#send').html(time+"S后再次发送");
                            time--;
                            return false;
                            sends.checked = 0;
                        }
                        $('#send').addClass('send0').removeClass('send1');
                        timeCountDown();
                        
                    }
                } else if(data.reg == 3){
                    alert('请输入加入会员时填写的手机号！');
                } else {
                    alert('验证码发送失败,请联系管理员');
                }

            });

        }
    }
</script>
</body>
</html>
